class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        if(nums.size()==0) return{-1,-1};
        int l=leftRange(nums,target);
        int r=rightRange(nums,target);
        return {l,r};
    }
    int leftRange(vector<int>& nums, int target) {
        int l = 0, r = nums.size() - 1;
        while (l < r) {
            int mid = l + (r - l) / 2;
            if (nums[mid] < target)
                l = mid + 1;
            else
                r = mid;
        }
        if (nums[l] == target)
            return l;
        else
            return -1;
    }
    int rightRange(vector<int>& nums, int target) {
        int l = 0, r = nums.size() - 1;
        while (l < r) {
            int mid = l + (r - l + 1) / 2;
            if (nums[mid] > target)
                r = mid - 1;
            else
                l = mid;
        }
        if (nums[l] == target)
            return l;
        else
            return -1;
    }
};